package top.ikunikun.common;

import lombok.Data;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * 全局返回对象
 * @param <T>
 */
@Data
public class Result <T> implements Serializable {
    private Integer code;
    private String msg;
    private T data;
    private Map map = new HashMap();
    public static <T> Result<T> success(T object){
        Result<T> r = new Result<T>();
        r.data = object;
        r.code = 1;
        return r;
    }
    public static <T> Result<T> error(String msg){
        Result<T> r = new Result<T>();
        r.msg = msg;
        r.code = 0;
        return r;
    }
    public Result<T> add(String key, Object value){
        this.map.put(key, value);
        return this;
    }
}
